package com.tsinghuabigdata.edu.ddmath.commons.newbieguide;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Handler;

import com.tsinghuabigdata.edu.ddmath.util.AppLog;

/**
 * 浮层引导页管理
 */
public class NewbieGuideManager {

    private static final String TAG = "newbie_guide";

    private Activity mActivity;
    private NewbieGuide mNewbieGuide;
    private SharedPreferences sp;
    private String activityname;

    public NewbieGuideManager(Activity activity, String classname ) {
        mNewbieGuide = new NewbieGuide(activity);
        mNewbieGuide.setEveryWhereTouchable( false );
        sp = activity.getSharedPreferences(TAG, Activity.MODE_PRIVATE);
        mActivity = activity;
        activityname = classname;
    }

    public NewbieGuide getNewbieGuide(){
        return mNewbieGuide;
    }

//    public NewbieGuideManager addView(View view, int shape, String tips, String btntext ) {
//
//        //高亮区域
//        mNewbieGuide.addHighLightView(view, shape);
//
//        //文本提示
//        mNewbieGuide.addMessage( tips, ScreenUtils.dpToPx(mActivity, 150), 400 );
//
//        //按钮
//        mNewbieGuide.addBtnTv( btntext, 600, 700 );
//
//        return this;
//    }

    /**
     * 第一步时调用
     */
    public void show() {
        mNewbieGuide.show();

        //
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(TAG + activityname, false);
        editor.apply();

        AppLog.d("TTT", "mActivity.getLocalClassName() = " + mActivity.getLocalClassName() );
    }

    /**
     * 其他步调用
     * @param delayTime
     */

    public void show(int delayTime) {

        if( delayTime < 50 )
            delayTime = 50;

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mNewbieGuide.show();
            }
        }, delayTime);
    }

    public void showWithListener(NewbieGuide.OnGuideChangedListener onGuideChangedListener) {
        mNewbieGuide.setOnGuideChangedListener(onGuideChangedListener);
    }

    /**
     * 判断新手引导也是否已经显示了
     */
    public static boolean isNeverShowed(Activity activity, String classname ) {
       return activity.getSharedPreferences(TAG, Activity.MODE_PRIVATE).getBoolean(TAG + classname, true);
    }

}
